package cate.game.role.res.guild.po.my;

import cate.common.table.d.GDGuild;
import cate.game.role.RoleDependent;
import cate.game.role.res.guild.msg.member.GuildPerformanceResp;
import cate.game.role.res.guild.po.GuildPerformancePO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "我在公会中的表现")
public class MyGuildPerformancePO extends RoleDependent {

    @NoteField(value = "担任职位")
    public byte position;

    @JsonIgnore
    @NoteField(value = "今日活跃")
    public long activeToday;

    @JsonIgnore
    @NoteField(value = "当周活跃")
    public long activeWeek;

    @NoteField(value = "上次捐献时间")
    public long lastDonateTime;

    @NoteField(value = "上次贡献活跃时间")
    public long lastActiveTime;

    @NoteField(value = "累计活跃")
    public long activeTotal;

    @NoteField(value = "日常任务完成量")
    public long dayTaskCount;

    @NoteField(value = "今日获得贡献总值")
    public long todayPValue;

    @NoteField(value = "累计贡献总值")
    public long totalPValue;

    public void noticeUpdate() {
        role.sendNow(new GuildPerformanceResp(this));
    }

    /**
     * 增加个人的公会活跃度
     */
    public void addActive(long active) {
        lastActiveTime = System.currentTimeMillis();
        activeToday += active;
        activeTotal += active;
        activeWeek += active;
        this.noticeUpdate();
        doSync();
    }

    /**
     * 把我的公会表现数据同步到公会成员信息中除了职位信息的部分
     */
    public void doSync() {
        if (role.getRes().guild.checkGuild().ok()) {
            role.getRes().guild.getMember().performance.read(role);
        }
    }

    /**
     * 读取公会成员信息 获取职位信息
     */
    public void read(GuildPerformancePO performance) {
        this.position = performance.position;
    }


    /**
     * 离开公会时清除部分公会数据
     */
    public void clear() {
        position = GDGuild.position.MEMBER;
        activeToday = 0L;
        activeTotal = 0L;
        activeWeek = 0L;
        todayPValue = 0L;
    }

    public void snycDayTask(int dayTaskCount) {
        this.dayTaskCount = dayTaskCount;
        role.getRes().guild.getMember().performance.dayTaskCount = this.dayTaskCount;
    }

    @Override
    public void onDaySpan(boolean silence) {
        super.onDaySpan(silence);
        todayPValue = 0L;
        activeToday = 0L;
    }

    public void addPValue(int pNum) {
        this.todayPValue += pNum;
        this.totalPValue += pNum;
        doSync();
    }
}
